package com.saftalk;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import net.sf.jsr107cache.Cache;
import net.sf.jsr107cache.CacheException;
import net.sf.jsr107cache.CacheFactory;
import net.sf.jsr107cache.CacheManager;

import com.google.appengine.api.memcache.jsr107cache.GCacheFactory;

public class BaseServlet extends HttpServlet {
	
	private static final long serialVersionUID = 7557966060422825286L;
	protected Cache cache;
	
	@Override
	public void init(ServletConfig config) throws ServletException {
		super.init(config);
		

        
		Map props = new HashMap();
        props.put(GCacheFactory.EXPIRATION_DELTA, 120);

        try {
            CacheFactory cacheFactory = CacheManager.getInstance().getCacheFactory();
            cache = cacheFactory.createCache(props);
        } catch (CacheException e) {
        	e.printStackTrace();
        	throw new ServletException("Failed to init cache");
        }
	}

}
